<template>
  <a-modal v-model="visible" title="编辑计划" @ok="handleOk" width="75%">
    <a-form-model ref="rulesForm" :model="form" :rules="rules" :labelCol="{ lg: { span: 5 }, sm: { span: 7 } }" :wrapperCol="{ lg: { span: 10 }, sm: { span: 17 } }">
      <a-form-model-item label="款号">
        <span>{{ form.productCode }}</span>
      </a-form-model-item>
      <a-form-model-item label="颜色">
        <span>{{ form.productColor }}/{{ form.productColorName }}</span>
      </a-form-model-item>
      <a-form-model-item label="品牌">
        <p>{{ arcBrandText(form.arcBrand, arcBrandsList) }}</p>
      </a-form-model-item>
      <!-- <a-form-model-item label="品牌">
        <p>{{ brandText(form.brand, brandList) }}</p>
      </a-form-model-item> -->
      <a-form-model-item label="波段">
        <p>{{ bandText(form.bandId, bandsList) }}</p>
      </a-form-model-item>
      <a-form-model-item label="预计入库时间" prop="preEntryTime">
        <a-date-picker allowClear v-model="form.preEntryTime" style="width:100%;" @change="onChangeEntryTime" />
      </a-form-model-item>
      <a-form-model-item label="预计预分开始时间" prop="preAssignedBeginTime">
        <a-date-picker allowClear v-model="form.preAssignedBeginTime" style="width:100%;" @change="onChangeBeginTime" />
      </a-form-model-item>
      <a-form-model-item label="预分结束时间" prop="preAssignedEndTime">
        <a-date-picker allowClear v-model="form.preAssignedEndTime" style="width:100%;" @change="onChangeEndTime" />
      </a-form-model-item>
      <a-form-model-item label="预计生产量">
        <span>{{ form.preQty }}</span>
      </a-form-model-item>
      <a-form-model-item label="生产调节" pro="adjustQty">
        <a-input-number v-model="form.adjustQty" />
      </a-form-model-item>
      <a-form-model-item label="实际生产量">
        <span>{{ form.qty }}</span>
      </a-form-model-item>
      <a-form-model-item label="预配仓库存数量">
        <span>{{ form.ypsl }}</span>
      </a-form-model-item>
      <a-form-model-item label="新品仓库存数量">
        <span>{{ form.xpsl }}</span>
      </a-form-model-item>
      <a-form-model-item label="已配数量">
        <span>{{ form.allotsl }}</span>
      </a-form-model-item>
      <a-form-model-item label="配货状态">
        <span>{{ form.allotstatus | allotstatus }}</span>
      </a-form-model-item>
      <a-form-model-item label="发货时间" prop="preAssigneDeliverTime">
        <a-date-picker allowClear v-model="form.deliverTime" style="width:100%;" @change="onChangeDeliverTime" />
      </a-form-model-item>
      <a-form-model-item label="入库数量">
        <span>{{ form.inQty }}</span>
      </a-form-model-item>
      <a-form-model-item label="发货波段">
        <a-input v-model="form.sendBand" />
      </a-form-model-item>
      <a-form-model-item label="备注">
        <a-textarea v-model="form.remark" :auto-size="{ minRows: 3, maxRows: 5 }" />
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>
<script>
import moment from 'moment'
import { saveAssignedDetail } from '@/api/goods/preAssigned'
import { queryDim } from '@/api/goods'
export default {
  props: ['brandList', 'bandsList', 'arcBrandsList', 'brandList'],
  data() {
    return {
      visible: false,
      yearShowOne: false,
      labelCol: { span: 4 },
      wrapperCol: { span: 14 },
      form: {},
      rules: {
        preEntryTime: [{ required: true, message: '请选择预计入库时间' }],
        preAssignedBeginTime: [{ required: true, message: '请选择预计预分开始时间' }],
        preAssignedEndTime: [{ required: true, message: '请选择预分结束时间' }],
        adjustQty: [{ required: true, message: '请输入生产调节' }]
      },
      editRecord: {}
    }
  },
  filters: {
    allotstatus(key) {
      switch (key) {
        case 0:
          return '未入库'
        case 1:
          return '部分入库'
        case 2:
          return '全部入库'
        case 3:
          return '配货中'
        case 4:
          return '配货完成'
        case 5:
          return '发货完成'
      }
    }
  },
  computed: {
    arcBrandText(text, list) {
      return (text, list) => {
        let res = list.filter(e => e.id == text)
        if (res.length > 0) {
          return res[0].attribname
        } else {
          return text
        }
      }
    },
    brandText(text, list) {
      return (text, list) => {
        let res = list.filter(e => e.id == text)
        if (res.length > 0) {
          return res[0].attribname
        } else {
          return text
        }
      }
    },
    bandText(text, list) {
      return (text, list) => {
        let res = list.filter(e => e.id == text)
        if (res.length > 0) {
          return res[0].attribname
        } else {
          return text
        }
      }
    }
  },
  methods: {
    show(record) {
      this.form = record
      this.visible = true
    },
    onChangeEntryTime(date, dateString) {
      this.form.preEntryTime = dateString
    },
    onChangeBeginTime(date, dateString) {
      this.form.preAssignedBeginTime = dateString
    },
    onChangeEndTime(date, dateString) {
      this.form.preAssignedEndTime = dateString
    },
    onChangeDeliverTime(date, dateString) {
      this.form.deliverTime = dateString
    },
    // 编辑确认
    handleOk() {
      this.$refs.rulesForm.validate(valid => {
        console.log(valid)
        if (valid) {
          console.log(this.form)
          let params = {
            requestData: this.form
          }
          saveAssignedDetail(params).then(res => {
            if (res.code == 0) {
              this.$message.success('编辑成功！')
              this.visible = false
              this.$emit('updateTable')
            } else {
              this.$message.warning(res.msg)
            }
          })
        } else {
        }
      })
    }
  }
}
</script>
